package com.zmn.oms.dubbo.impl.zmn.normal.work.master;


import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.model.vo.work.OperatePermissionVO;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkOperatePermissionBService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto.ResponseDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.common.utils.response.ResponseUtil;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.oms.business.interfaces.messageV1.SendOrderMessageService;
import com.zmn.oms.business.interfaces.orderamount.OrderDiscountCalcBService;
import com.zmn.oms.common.constant.*;
import com.zmn.oms.common.dto.OmsOperator;
import com.zmn.oms.dubbo.dto.common.express.ExpressCompanyDRO;
import com.zmn.oms.dubbo.dto.common.part.ApplyFactoryPartCheckDRO;
import com.zmn.oms.dubbo.dto.common.part.FactoryPartDRO;
import com.zmn.oms.dubbo.dto.common.part.FactoryPartPostCheckDRO;
import com.zmn.oms.dubbo.dto.common.part.FactoryPartPostDIO;
import com.zmn.oms.dubbo.dto.common.work.*;
import com.zmn.oms.dubbo.dto.zmn.part.fcpart.FcOrderPartRespDRO;
import com.zmn.oms.dubbo.impl.OmsBaseRemoteService;
import com.zmn.oms.dubbo.interfaces.zmn.normal.work.master.ZsNormalMasterWorkRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.bo.orderamount.DiscountConditionParamsDIO;
import com.zmn.oms.model.bo.orderamount.OrderAmountDIO;
import com.zmn.oms.model.bo.orderamount.ReCalcOrderAmountDIO;
import com.zmn.oms.model.dto.fcorderpart.ApplyFactoryPartCheckDTO;
import com.zmn.oms.model.dto.fcorderpart.FcOrderPartRespDTO;
import com.zmn.oms.model.dto.fcorderpart.OrderFactoryPartDTO;
import com.zmn.oms.model.dto.part.FactoryPartDTO;
import com.zmn.oms.model.dto.part.FactoryPartPostDTO;
import com.zmn.oms.model.dto.serviceitem.AddOrderServiceItemDTO;
import com.zmn.oms.model.dto.warranty.MasterWorkWarrantyDTO;
import com.zmn.oms.model.dto.work.masterwork.*;
import com.zmn.oms.model.dto.work.modify.OrderWarrantyDTO;
import com.zmn.oms.model.dto.work.modify.amount.ZsDiscountDTO;
import com.zmn.oms.model.dto.work.modify.must.ZsPartDTO;
import com.zmn.oms.model.entity.discount.OrderDiscount;
import com.zmn.oms.model.entity.factory.OrderFactory;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.services.interfaces.discount.OrderDiscountService;
import com.zmn.oms.services.interfaces.factory.OrderFactoryService;
import com.zmn.oms.services.interfaces.work.OrderWorkService;
import com.zmn.oms.zmn.business.interfaces.part.ZsOrderFactoryPartBService;
import com.zmn.oms.zmn.business.interfaces.work.OrderWorkModifyProductBService;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkBService;
import com.zmn.oms.zmn.business.interfaces.work.masterwork.ZsMasterWorkBService;
import com.zmn.oms.zmn.normal.business.interfaces.discount.ZsNormalOrderDiscountBService;
import com.zmn.oms.zmn.normal.business.interfaces.work.masterwork.ZsNormalMasterWorkBService;
import com.zmn.tapi.common.expressage.ExpressageCompany;
import com.zmn.tapi.dubbo.interfaces.expressage.ExpressageRemoteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 类描述：普通工单服务
 *
 * @author heciqi
 * @date 2018/11/21 19:37
 */
@Service(loadbalance = "roundrobin", timeout = 20000, retries = 2, version = DubboConsts.INTERFACE_VERSION)
public class ZsNormalMasterWorkRemoteServiceImpl extends OmsBaseRemoteService implements ZsNormalMasterWorkRemoteService {
    private static final Logger logger = LoggerFactory.getLogger(ZsNormalMasterWorkRemoteServiceImpl.class);

    private static final String TAG = "啄木鸟-普通工单-工程师工单dubbo接口";
    private static final String SMS_TEMPLATE_TO_FACTORY = "【言而有信售后平台】您好，%s。如有疑问请拨打商务合作热线：400-0665-315，感谢您对言而有信售后平台的支持与信任！";

    @Autowired
    private ZsMasterWorkBService zsMasterWorkBService;
    @Autowired
    private ZsNormalMasterWorkBService zsNormalMasterWorkBService;
    @Autowired
    private ZsOrderFactoryPartBService zsOrderFactoryPartBService;
    @Autowired
    private ZsNormalOrderDiscountBService zsNormalOrderDiscountBService;
    @Autowired
    private OrderFactoryService orderFactoryService;
    @Autowired
    private OrderWorkModifyProductBService orderWorkModifyProductBService;
    @Autowired
    private ZsOrderWorkBService zsOrderWorkBService;
    @Autowired
    private OrderWorkService orderWorkService;
    @Autowired
    private SendOrderMessageService sendOrderMessageService;
    @Autowired
    private ZsOrderWorkOperatePermissionBService orderWorkOperatePermissionBService;


//    @Reference(version = com.zmn.mer.dubbo.utils.DubboConsts.INTERFACE_VERSION, check = false)
//    private FactoryListRemoteService factoryListRemoteService;
    @Reference(version = com.zmn.tapi.dubbo.DubboConsts.INTERFACE_VERSION, check = false)
    private ExpressageRemoteService expressageRemoteService;

    @Autowired
    private OrderDiscountCalcBService orderDiscountCalcBService;
    @Autowired
    private OrderDiscountService orderDiscountService;
    /**
     * 检查工程师是否有未完成进行中工单
     * @param checkMasterWorkStatusDIO
     */
    @Override
    public ResponseDTO<Boolean> checkMasterWorkStatus(CheckMasterWorkStatusDIO checkMasterWorkStatusDIO) {
        ResponseDTO<Boolean> responseDTO;

        try {
            boolean ret = zsMasterWorkBService.checkWorkStatus(checkMasterWorkStatusDIO.getMasterId(), checkMasterWorkStatusDIO.getStartTime(), checkMasterWorkStatusDIO.getEndTime());
            responseDTO = ResponseUtil.responseSuccess(ret, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工程师进行中工单
     *
     * @param masterWorkDIO
     */
    @Override
    public ResponseDTO<WorkListDRO> getWorkingList(MasterWorkDIO masterWorkDIO) {
        ResponseDTO responseDTO;

        try {
            WorkListDTO workListDTO = zsMasterWorkBService.getWorkingList(masterWorkDIO.getMasterId());
            WorkListDRO workListDRO = BeanMapper.map(workListDTO, WorkListDRO.class);
            responseDTO = ResponseUtil.responseSuccess(workListDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工程师完成工单
     *
     * @param masterWorkDIO
     */
    @Override
    public ResponseDTO<WorkListDRO> getCompleteWorkList(MasterWorkDIO masterWorkDIO) {
        ResponseDTO responseDTO;

        // 已完成工单限定在两个月内，上月和当月
        // 上个月1号到当前时间
        Date endDate = DateUtil.getNow();
        Date startDate = DateUtil.parse(DateUtil.getMonthFirstDay(DateUtil.addMonth(endDate, -1)), DateUtil.FORMAT_DEFAULT);
        try {
            WorkListDTO workListDTO = zsMasterWorkBService.getCompleteWorkList(masterWorkDIO.getPlat(),
                    masterWorkDIO.getMasterId(),startDate,endDate, masterWorkDIO.getStartIndex(), masterWorkDIO.getPageSize());
            WorkListDRO workListDRO = BeanMapper.map(workListDTO, WorkListDRO.class);
            responseDTO = ResponseUtil.responseSuccess(workListDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工单详情
     * @param masterWorkDIO
     */
    @Override
    public ResponseDTO<WorkDetailDRO> getWorkDetail(MasterWorkDIO masterWorkDIO) {
        ResponseDTO responseDTO;

        try {
            Long orderId = masterWorkDIO.getOrderId();
            if (orderId == null || orderId == 0) {
                orderId = masterWorkDIO.getWorkId();
            }

            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetail(masterWorkDIO.getPlat(),
                    orderId, masterWorkDIO.getWorkId(), masterWorkDIO.getMasterId(),
                    masterWorkDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);
            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工单简版详情
     * @param masterWorkDIO
     */
    @Override
    public ResponseDTO<WorkDetailDRO> getWorkSimpleDetail(MasterWorkDIO masterWorkDIO) {
        ResponseDTO responseDTO;

        try {
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkSimpleDetail(masterWorkDIO.getPlat(),
                    masterWorkDIO.getOrderId(), masterWorkDIO.getWorkId());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);
            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 历史工单详情
     * @param masterWorkDIO
     */
    @Override
    public ResponseDTO<WorkDetailDRO> getHisWorkDetail(MasterWorkDIO masterWorkDIO) {
        ResponseDTO responseDTO;

        try {
            WorkDetailDTO workDetail = zsMasterWorkBService.getHisWorkDetail(masterWorkDIO.getPlat(),
                    masterWorkDIO.getOrderId(), masterWorkDIO.getWorkId(), masterWorkDIO.getMasterId(),
                    masterWorkDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);
            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 检查工单优惠状态
     * @param masterWorkDIO
     */
    @Override
    public ResponseDTO checkDiscountStatus(MasterWorkDIO masterWorkDIO) {
        ResponseDTO responseDTO;

        try {
            zsMasterWorkBService.checkDiscountStatus(masterWorkDIO.getOrderId(), masterWorkDIO.getWorkId(),
                    masterWorkDIO.getMasterId());
            responseDTO = ResponseUtil.responseSuccess();
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }


    /**
     * 工程师领单
     *
     * @param masterTakeDIO
     */
    @Override
    public ResponseDTO<WorkListDRO> updateMasterTake(MasterTakeDIO masterTakeDIO) {
        ResponseDTO responseDTO;

        try {
            MasterTakeDTO masterTakeDTO = BeanMapper.map(masterTakeDIO, MasterTakeDTO.class);
            this.setLogParam(masterTakeDIO, masterTakeDTO);

            zsMasterWorkBService.updateMasterTake(masterTakeDTO);

            // 返回更新后的工单列表
            WorkListDTO workListDTO = zsMasterWorkBService.getWorkingList(masterTakeDIO.getMasterId());
            WorkListDRO workListDRO = BeanMapper.map(workListDTO, WorkListDRO.class);
            responseDTO = ResponseUtil.responseSuccess(workListDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工程师出发
     * @param masterLeaveDIO
     * @return
     */
    @Override
    public com.zmn.common.dto2.ResponseDTO<Boolean> updateMasterLeave(MasterLeaveDIO masterLeaveDIO) {
        com.zmn.common.dto2.ResponseDTO responseDTO;
        try {
            MasterLeaveDTO levaeDTO = BeanMapper.map(masterLeaveDIO, MasterLeaveDTO.class);
            this.setLogParam(masterLeaveDIO, levaeDTO);
            levaeDTO.setSessionId(masterLeaveDIO.getSessionId());

            zsMasterWorkBService.updateMasterLeave(levaeDTO);

            responseDTO = com.zmn.common.dto2.ResponseDTO.success();
        } catch (Exception e) {
            responseDTO = com.zmn.common.dto2.ResponseDTO.fail(e.getMessage());
        }

        return responseDTO;
    }

    /**
     * 上门
     *
     * @param masterVisitDIO
     * @return
     */
    @Override
    public ResponseDTO<MasterVisitResponseDRO> updateMasterVisit(MasterVisitDIO masterVisitDIO) {
        ResponseDTO responseDTO;

        try {
            MasterVisitDTO visitDTO = BeanMapper.map(masterVisitDIO, MasterVisitDTO.class);
            this.setLogParam(masterVisitDIO, visitDTO);

            MasterVisitResponseDTO visitResponseDTO = zsMasterWorkBService.updateMasterVisit(visitDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(masterVisitDIO.getPlat(),
                    masterVisitDIO.getOrderId(), masterVisitDIO.getWorkId(), masterVisitDIO.getMasterId(),
                    masterVisitDIO.getAgent());
            visitResponseDTO.setWorkDetail(workDetail);

            // 返回更新后的工单列表
            WorkListDTO workListDTO = zsMasterWorkBService.getWorkingList(masterVisitDIO.getMasterId());
            visitResponseDTO.setWorkList(workListDTO);

            MasterVisitResponseDRO masterVisitResponseDRO = BeanMapper.map(visitResponseDTO, MasterVisitResponseDRO.class);

            return ResponseUtil.responseSuccess(masterVisitResponseDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 改价格
     * @param changePriceDIO
     */
    @Override
    public ResponseDTO<WorkDetailDRO> updatePrice(ChangePriceDIO changePriceDIO) {
        ResponseDTO responseDTO;

        try {
            ChangePriceDTO changePriceDTO = BeanMapper.map(changePriceDIO, ChangePriceDTO.class);
            this.setLogParam(changePriceDIO, changePriceDTO);

            zsMasterWorkBService.updatePrice(changePriceDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(changePriceDIO.getPlat(),
                    changePriceDIO.getOrderId(), changePriceDIO.getWorkId(), changePriceDIO.getMasterId(),
                    changePriceDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            return ResponseUtil.responseSuccess(workDetailDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 标记为使用配件
     * @param usePartDIO
     */
    @Override
    public ResponseDTO<WorkDetailDRO> updateUsePart(BaseRequestDIO usePartDIO) {
        ResponseDTO responseDTO;

        try {
            UsePartDTO usePartDTO = BeanMapper.map(usePartDIO, UsePartDTO.class);
            this.setLogParam(usePartDIO, usePartDTO);

            zsMasterWorkBService.updateUsePart(usePartDTO);

            return ResponseUtil.responseSuccess();
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 获取最大优惠金额
     * @param getMaxDiscountDIO
     */
    @Override
    @Deprecated
    public ResponseDTO<Integer> getMaxDiscount(BaseRequestDIO getMaxDiscountDIO) {
        ResponseDTO responseDTO;
        try {
/*            Integer maxDiscountAmount = zsNormalOrderDiscountBService.getMaxDiscountAmount(
                    getMaxDiscountDIO.getOrderId(), getMaxDiscountDIO.getWorkId(),
                    OrderConsts.ORDER_OP_TYPE_DISCOUNT_LEVEL_ONE, FicoConsts.ORDER_IN_DISCOUNT_CATEG_ARTIFICIAL_MASTER);*/
            OrderWork dbOrderWork = orderWorkService.findOrderWorkByKey(getMaxDiscountDIO.getOrderId(), getMaxDiscountDIO.getWorkId());
            List<OrderDiscount> orderDiscounts = Lists.newArrayList();
            if (NumberUtil.isNotNullOrZero(dbOrderWork.getDiscountAmount())) {
                orderDiscounts = orderDiscountService.listByOrderId(getMaxDiscountDIO.getOrderId());
            }

            ReCalcOrderAmountDIO calcOrderAmountDIO = new ReCalcOrderAmountDIO();
            calcOrderAmountDIO.setOrderAmountDIO(BeanMapper.map(dbOrderWork, OrderAmountDIO.class));
            calcOrderAmountDIO.setDiscountConditionParamsDIO(BeanMapper.map(dbOrderWork, DiscountConditionParamsDIO.class));
            calcOrderAmountDIO.setOrderDiscountList(orderDiscounts);
            Integer artificialMaxDiscount = orderDiscountCalcBService.getArtificialMaxDiscount(TriggerAmountChangeEnum.ARTIFICIAL_MASTER_DISCOUNT, calcOrderAmountDIO);

            return ResponseUtil.responseSuccess(artificialMaxDiscount, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 优惠
     * @param procDiscountDIO
     */
    @Override
    public ResponseDTO<WorkDetailDRO> procDiscount(ProcDiscountDIO procDiscountDIO) {
        ResponseDTO responseDTO;

        try {
            OrderWork orderWork = orderWorkService.findOrderWorkByKey(procDiscountDIO.getOrderId(), procDiscountDIO.getWorkId());
            if (orderWork.getStatus() >= OrderStatusConsts.WORK_STATUS_COMPLETE) {
                return ResponseUtil.responseFail("完成后不可操作优惠");
            }

            ZsDiscountDTO discountDTO = new ZsDiscountDTO();
            this.setLogParam(procDiscountDIO, discountDTO);

            discountDTO.setDiscountAmount(procDiscountDIO.getDiscountAmount());
            zsMasterWorkBService.saveDiscount(discountDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(procDiscountDIO.getPlat(),
                    procDiscountDIO.getOrderId(), procDiscountDIO.getWorkId(), procDiscountDIO.getMasterId(),
                    procDiscountDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            return ResponseUtil.responseSuccess(workDetailDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 纸质保修卡
     *
     * @param manualCodeDIO
     * @return
     */
    @Override
    public ResponseDTO<WorkDetailDRO> updateManualCode(ManualCodeDIO manualCodeDIO) {
        ResponseDTO responseDTO;

        try {
            ManualCodeDTO manualCodeDTO = BeanMapper.map(manualCodeDIO, ManualCodeDTO.class);
            this.setLogParam(manualCodeDIO, manualCodeDTO);

            zsMasterWorkBService.updateManualCode(manualCodeDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(manualCodeDIO.getPlat(),
                    manualCodeDIO.getOrderId(), manualCodeDIO.getWorkId(), manualCodeDIO.getMasterId(),
                    manualCodeDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工程师备注
     *
     * @param masterRemarkDIO
     * @return
     */
    @Override
    public ResponseDTO<MasterRemarkResponseDRO> updateMasterRemark(MasterRemarkDIO masterRemarkDIO) {
        ResponseDTO responseDTO;

        try {
            MasterRemarkDTO masterRemarkDTO = BeanMapper.map(masterRemarkDIO, MasterRemarkDTO.class);
            this.setLogParam(masterRemarkDIO, masterRemarkDTO);
            logger.info("工程师修改备注：start");
            boolean refreshWorkList = zsMasterWorkBService.updateMasterRemark(masterRemarkDTO);
            logger.info("工程师修改备注：end");
            MasterRemarkResponseDRO masterRemarkResponseDRO = new MasterRemarkResponseDRO();

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(masterRemarkDIO.getPlat(),
                    masterRemarkDIO.getOrderId(), masterRemarkDIO.getWorkId(), masterRemarkDIO.getMasterId(),
                    masterRemarkDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);
            masterRemarkResponseDRO.setWorkDetail(workDetailDRO);

            // 工单列表需要刷新
            if (refreshWorkList) {
                // 返回更新后的工单列表
                WorkListDTO workListDTO = zsMasterWorkBService.getWorkingList(masterRemarkDIO.getMasterId());
                WorkListDRO workListDRO = BeanMapper.map(workListDTO, WorkListDRO.class);
                masterRemarkResponseDRO.setWorkList(workListDRO);
            }

            responseDTO = ResponseUtil.responseSuccess(masterRemarkResponseDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工程师用配件
     * @param usePartDIO
     */
    @Override
    public ResponseDTO<WorkDetailDRO> updatePart(UsePartDIO usePartDIO) {
        ResponseDTO responseDTO;

        try {
            ZsPartDTO zsPartDTO = BeanMapper.map(usePartDIO, ZsPartDTO.class);
            this.setLogParam(usePartDIO, zsPartDTO);
            logger.info("保存工程师配件zsPartDTO[{}]", zsPartDTO);
            zsMasterWorkBService.updatePart(zsPartDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(usePartDIO.getPlat(),
                    usePartDIO.getOrderId(), usePartDIO.getWorkId(), usePartDIO.getMasterId(), usePartDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        }
        catch (Exception e) {
            logger.error("保存工程师配件失败", e);
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工程师取消配件
     * @param cancelPartDIO
     */
    @Override
    public ResponseDTO<WorkDetailDRO> cancelPart(CancelPartDIO cancelPartDIO) {
        ResponseDTO responseDTO;

        try {
            ZsPartDTO zsPartDTO = new ZsPartDTO();
            this.setLogParam(cancelPartDIO, zsPartDTO);
            zsPartDTO.setUsed(GlobalConsts.NO);

            zsMasterWorkBService.cancelPart(zsPartDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(cancelPartDIO.getPlat(),
                    cancelPartDIO.getOrderId(), cancelPartDIO.getWorkId(), cancelPartDIO.getMasterId(),
                    cancelPartDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 申请厂商配件操作检查
     * @param baseRequestDIO
     * @return
     */
    @Override
    public ResponseDTO<ApplyFactoryPartCheckDRO> applyFactoryPartCheck(BaseRequestDIO baseRequestDIO) {
        ResponseDTO responseDTO;

        try {
            ApplyFactoryPartCheckDTO checkDTO = zsOrderFactoryPartBService.applyFcPartCheck(baseRequestDIO.getOrderId());
            ApplyFactoryPartCheckDRO checkDRO = BeanMapper.map(checkDTO, ApplyFactoryPartCheckDRO.class);
            responseDTO = ResponseUtil.responseSuccess(checkDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工程师申请厂家配件
     * @param orderFactoryPartDIO
     */
    @Override
    public ResponseDTO<FactoryPartDRO> applyFactoryPart(OrderFactoryPartDIO orderFactoryPartDIO) {
        ResponseDTO responseDTO;

        try {
            OrderFactoryPartDTO orderFactoryPartDTO = BeanMapper.map(orderFactoryPartDIO, OrderFactoryPartDTO.class);
            this.setLogParam(orderFactoryPartDIO, orderFactoryPartDTO);

            zsOrderFactoryPartBService.applyFcPart(orderFactoryPartDTO);

            /*OrderFactory orderFactory = orderFactoryService.findOrderFactoryByKey(orderFactoryPartDTO.getOrderId());
            com.zmn.common.dto2.ResponseDTO<FactoryDRO> resultDTO = factoryListRemoteService.getFactoryById(orderFactory.getFactoryId());

            if (resultDTO.isSuccess()) {
                FactoryDRO factoryDRO = resultDTO.getData();
                String phone = factoryDRO.getMobile();
                String msg = String.format("工单%s申请了厂商配件，请您及时审核", orderFactoryPartDIO.getOrderId());
                //MQPushUtil.sendBizSmsInfo(phone, String.format(SMS_TEMPLATE_TO_FACTORY, msg)); 2019-12-26 需求暂时删除
            }
            else {
                logger.info(String.format("【申请厂家配件】短信通知发送失败，%s", resultDTO.getMessage()));
            }*/

            responseDTO = ResponseUtil.responseSuccess("OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工程师获取需要返厂的配件
     * @param baseRequestDIO
     * @return
     */
    @Override
    public ResponseDTO<FactoryPartDRO> getToPostReturnFcPart(BaseRequestDIO baseRequestDIO) {
        ResponseDTO responseDTO;

        try {
            OmsOperator omsOperator = BeanMapper.map(baseRequestDIO, OmsOperator.class);
            this.setLogParam(baseRequestDIO, omsOperator);

            List<FactoryPartDTO> fcPartDTOList = zsOrderFactoryPartBService.getToPostReturnFcPart(omsOperator);
            List<FactoryPartDRO> fcPartDROList = BeanMapper.mapList(fcPartDTOList, FactoryPartDRO.class);

            responseDTO = ResponseUtil.responseSuccessItems(fcPartDROList);
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 邮寄配件（旧件返厂）
     * @param factoryPartPostDIO
     * @return
     */
    @Override
    public ResponseDTO<FactoryPartPostCheckDRO> postReturnFcPart(FactoryPartPostDIO factoryPartPostDIO) {
        ResponseDTO responseDTO;

        try {
            FactoryPartPostDTO factoryPartPostDTO = BeanMapper.map(factoryPartPostDIO, FactoryPartPostDTO.class);
            this.setLogParam(factoryPartPostDIO, factoryPartPostDTO);

            zsOrderFactoryPartBService.updatePostReturnFcPart(factoryPartPostDTO);
            // 需要返回是否还存在未邮寄的返厂配件
            boolean contains = zsOrderFactoryPartBService.containsToPostReturnFcPart(factoryPartPostDTO.getOrderId());
            FactoryPartPostCheckDRO checkDRO = new FactoryPartPostCheckDRO();
            checkDRO.setContainsReturnFcPartWaiting4Post(contains ? GlobalConsts.YES : GlobalConsts.NO);

            OrderFactory orderFactory = orderFactoryService.findOrderFactoryByKey(factoryPartPostDIO.getOrderId());
            /*com.zmn.common.dto2.ResponseDTO<FactoryDRO> resultDTO = factoryListRemoteService.getFactoryById(orderFactory.getFactoryId());

            if (resultDTO.isSuccess()) {
                FactoryDRO factoryDRO = resultDTO.getData();
                String phone = factoryDRO.getMobile();
                String msg = String.format("工单%s的旧件已经邮寄，快递单号：%s，您可登录系统查看物流信息",
                        factoryPartPostDIO.getOrderId(), factoryPartPostDTO.getExpressCode());
                //MQPushUtil.sendBizSmsInfo(phone, String.format(SMS_TEMPLATE_TO_FACTORY, msg)); 2019-12-26 需求暂时删除
            }
            else {
                logger.info(String.format("【旧件返厂】短信通知发送失败，%s", resultDTO.getMessage()));
            }*/

            responseDTO = ResponseUtil.responseSuccess(checkDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 获取厂商配件物流信息
     * @param baseRequestDIO
     * @return
     */
    @Override
    public ResponseDTO<FcOrderPartRespDRO> getExpressParts(BaseRequestDIO baseRequestDIO) {
        ResponseDTO responseDTO;

        try {
            FcOrderPartRespDTO fcOrderPartRespDTO = zsOrderFactoryPartBService.getExpressParts(baseRequestDIO.getOrderId());
            FcOrderPartRespDRO fcOrderPartRespDRO = BeanMapper.map(fcOrderPartRespDTO, FcOrderPartRespDRO.class);
            responseDTO = ResponseUtil.responseSuccess(fcOrderPartRespDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 通过ID查询配件物流信息，用于修改快递记录
     * @param fcOrderPartId
     * @return
     */
    @Override
    public ResponseDTO<FactoryPartDRO> getExpressPartById(Integer fcOrderPartId) {
        ResponseDTO responseDTO;

        try {
            FactoryPartDTO factoryPartDTO = zsOrderFactoryPartBService.getExpressPartById(fcOrderPartId);
            FactoryPartDRO factoryPartDRO = BeanMapper.map(factoryPartDTO, FactoryPartDRO.class);
            responseDTO = ResponseUtil.responseSuccess(factoryPartDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 获取快递公司
     */
    @Override
    public ResponseDTO<ExpressCompanyDRO> getExpressesCompanyList() {
        Map<String, String> map = expressageRemoteService.listCompany().getData().stream().collect(Collectors.toMap(ExpressageCompany::getCode, ExpressageCompany::getName));
        List<ExpressCompanyDRO> list = new LinkedList();
        for (String key : map.keySet()) {
            ExpressCompanyDRO obj = new ExpressCompanyDRO();
            obj.setCode(key);
            obj.setName(map.get(key));
            if (!obj.getName().contains("订单")) {
                list.add(obj);
            }
        }
        return ResponseUtil.responseSuccess(list, "OK");
    }

    /**
     * 保修项
     * @param procWarrantyDIO
     */
    @Override
    public ResponseDTO<WorkDetailDRO> updateWarranty(ProcWarrantyDIO procWarrantyDIO) {
        ResponseDTO responseDTO;

        try {
            OrderWarrantyDTO orderWarrantyDTO = BeanMapper.map(procWarrantyDIO, OrderWarrantyDTO.class);
            this.setLogParam(procWarrantyDIO, orderWarrantyDTO);

            zsMasterWorkBService.updateWarranty(orderWarrantyDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(procWarrantyDIO.getPlat(),
                    procWarrantyDIO.getOrderId(), procWarrantyDIO.getWorkId(), procWarrantyDIO.getMasterId(),
                    procWarrantyDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 服务项
     * @param procServiceItemDIO
     */
    @Override
    public ResponseDTO<WorkDetailDRO> updateServiceItem(ProcServiceItemDIO procServiceItemDIO) {
        ResponseDTO responseDTO;

        try {
            AddOrderServiceItemDTO addOrderServiceItemDTO = BeanMapper.map(procServiceItemDIO, AddOrderServiceItemDTO.class);
            addOrderServiceItemDTO.setQuotationType(GlobalConsts.OPERATE_USER_TYPE_MASTER);
            this.setLogParam(procServiceItemDIO, addOrderServiceItemDTO);
            zsMasterWorkBService.updateServiceItem(addOrderServiceItemDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(procServiceItemDIO.getPlat(),
                    procServiceItemDIO.getOrderId(), procServiceItemDIO.getWorkId(), procServiceItemDIO.getMasterId(),
                    procServiceItemDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 贴花照片
     *
     * @param orderImageDIO
     */
    @Override
    public ResponseDTO updateAppliqueImage(OrderImageDIO orderImageDIO) {
        ResponseDTO responseDTO;

        try {
            OrderImageDTO orderImageDTO = BeanMapper.map(orderImageDIO, OrderImageDTO.class);
            this.setLogParam(orderImageDIO, orderImageDTO);

            zsMasterWorkBService.updateAppliqueImage(orderImageDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(orderImageDIO.getPlat(),
                    orderImageDIO.getOrderId(), orderImageDIO.getWorkId(), orderImageDIO.getMasterId(),
                    orderImageDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工单照片
     *
     * @param orderImageDIO
     */
    @Override
    public ResponseDTO updateOrderImage(OrderImageDIO orderImageDIO) {
        ResponseDTO responseDTO;

        try {
            OrderImageDTO orderImageDTO = BeanMapper.map(orderImageDIO, OrderImageDTO.class);
            this.setLogParam(orderImageDIO, orderImageDTO);

            zsMasterWorkBService.updateOrderImage(orderImageDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(orderImageDIO.getPlat(),
                    orderImageDIO.getOrderId(), orderImageDIO.getWorkId(), orderImageDIO.getMasterId(),
                    orderImageDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 工单工程师照片
     *
     * @param orderImageDIO
     */
    @Override
    public ResponseDTO updateMasterImage(OrderImageDIO orderImageDIO) {
        ResponseDTO responseDTO;

        try {
            OrderImageDTO orderImageDTO = BeanMapper.map(orderImageDIO, OrderImageDTO.class);
            this.setLogParam(orderImageDIO, orderImageDTO);

            zsMasterWorkBService.updateMasterImage(orderImageDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(orderImageDIO.getPlat(),
                    orderImageDIO.getOrderId(), orderImageDIO.getWorkId(), orderImageDIO.getMasterId(),
                    orderImageDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 完成工单
     *
     * @param completeOrderDIO
     */
    @Override
    public ResponseDTO<WorkListDRO> completeOrder(CompleteOrderDIO completeOrderDIO) {
        ResponseDTO responseDTO;

        try {
            CompleteDTO completeDTO = BeanMapper.map(completeOrderDIO, CompleteDTO.class);
            this.setLogParam(completeOrderDIO, completeDTO);

            // 检测完成
            zsNormalMasterWorkBService.checkComplete(completeDTO);
            // 完成
            zsNormalMasterWorkBService.completeOrder(completeDTO);

            // 返回更新后的工单列表
            WorkListDTO workListDTO = zsMasterWorkBService.getWorkingList(completeOrderDIO.getMasterId());
            WorkListDRO workListDRO = BeanMapper.map(workListDTO, WorkListDRO.class);
            responseDTO = ResponseUtil.responseSuccess(workListDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 记录工程师联系用户
     *
     * @param contactUserDIO
     */
    @Override
    public ResponseDTO saveContactUser(ContactUserDIO contactUserDIO) {
        ResponseDTO responseDTO;

        try {
            ContactUserDTO contactUserDTO = BeanMapper.map(contactUserDIO, ContactUserDTO.class);
            this.setLogParam(contactUserDIO, contactUserDTO);

            zsMasterWorkBService.saveContactUser(contactUserDTO);

            responseDTO = ResponseUtil.responseSuccess();
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 查询会员单审核
     *
     * @param getMemberReviewDIO
     */
    @Override
    public ResponseDTO<MemberReviewDRO> getMemberReview(BaseRequestDIO getMemberReviewDIO) {
        ResponseDTO responseDTO;

        try {
            MemberReviewDTO memberReviewDTO = zsMasterWorkBService.getMemberReview(getMemberReviewDIO.getPlat(),
                    getMemberReviewDIO.getOrderId(), getMemberReviewDIO.getWorkId(), getMemberReviewDIO.getMasterId());
            MemberReviewDRO memberReviewDRO = BeanMapper.map(memberReviewDTO, MemberReviewDRO.class);
            responseDTO = ResponseUtil.responseSuccess(memberReviewDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 审核会员单
     *
     * @param procMemberReviewDIO
     */
    @Override
    public ResponseDTO procMemberReview(ProcMemberReviewDIO procMemberReviewDIO) {
        ResponseDTO responseDTO;

        try {
            ProcMemberReviewDTO procMemberReviewDTO = BeanMapper.map(procMemberReviewDIO, ProcMemberReviewDTO.class);
            this.setLogParam(procMemberReviewDIO, procMemberReviewDTO);

            responseDTO = ResponseUtil.responseSuccess("OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    @Override
    public ResponseDTO<MasterWorkWarrantyDRO> getWorkWarranty(MasterWorkDIO masterWorkDIO) {
        ResponseDTO responseDTO;

        try {
            MasterWorkWarrantyDTO masterWorkWarrantyDTO = zsMasterWorkBService.getWorkWarranty(masterWorkDIO.getOrderId(),
                    masterWorkDIO.getWorkId());
            MasterWorkWarrantyDRO masterWorkWarrantyDRO = BeanMapper.map(masterWorkWarrantyDTO, MasterWorkWarrantyDRO.class);
            responseDTO = ResponseUtil.responseSuccess(masterWorkWarrantyDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    @Override
    public ResponseDTO<MasterWorkVisitQrCodeDRO> getWorkVisitQrCode(MasterWorkDIO masterWorkDIO) {
        ResponseDTO responseDTO;

        try {
            MasterWorkVisitQrCodeDTO masterWorkVisitQrCodeDTO = zsMasterWorkBService.getWorkVisitQrCode(
                    masterWorkDIO.getOrderId(), masterWorkDIO.getWorkId());
            MasterWorkVisitQrCodeDRO masterWorkVisitQrCodeDRO = BeanMapper.map(masterWorkVisitQrCodeDTO,
                    MasterWorkVisitQrCodeDRO.class);
            responseDTO = ResponseUtil.responseSuccess(masterWorkVisitQrCodeDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    @Override
    public ResponseDTO<WorkDetailDRO> updateDutyTime(ModifyDutyTimeDIO modifyDutyTimeDIO) {
        ResponseDTO responseDTO;

        try {
            ModifyDutyTimeDTO modifyDutyTimeDTO = BeanMapper.map(modifyDutyTimeDIO, ModifyDutyTimeDTO.class);
            this.setLogParam(modifyDutyTimeDIO, modifyDutyTimeDTO);

            zsMasterWorkBService.updateDutyTime(modifyDutyTimeDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(modifyDutyTimeDIO.getPlat(),
                    modifyDutyTimeDIO.getOrderId(), modifyDutyTimeDIO.getWorkId(), modifyDutyTimeDIO.getMasterId(),
                    modifyDutyTimeDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            return ResponseUtil.responseSuccess(workDetailDRO, "OK");
        }
        catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 改派工程师
     *
     * @param changeMasterDIO
     */
    @Override
    public ResponseDTO<WorkListDRO> updateMaster(ChangeMasterDIO changeMasterDIO) {
        ResponseDTO responseDTO;

        try {
            OrderWork orderWork = orderWorkService.findOrderWorkByKey(changeMasterDIO.getOrderId(), changeMasterDIO.getWorkId());
            if (orderWork.getStatus() >= OrderStatusConsts.WORK_STATUS_COMPLETE) {
                return ResponseUtil.responseFail("完成后不可转派");
            }

            ChangeMasterDTO changeMasterDTO = BeanMapper.map(changeMasterDIO, ChangeMasterDTO.class);
            this.setLogParam(changeMasterDIO, changeMasterDTO);
            zsMasterWorkBService.updateMaster(changeMasterDTO);

            // 返回更新后的工单列表
            WorkListDTO workListDTO = zsMasterWorkBService.getWorkingList(changeMasterDIO.getMasterId());
            WorkListDRO workListDRO = BeanMapper.map(workListDTO, WorkListDRO.class);
            responseDTO = ResponseUtil.responseSuccess(workListDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 修改订单报价
     */
    @Override
    public com.zmn.common.dto2.ResponseDTO<WorkDetailDRO> updateOrderQuotation(ModifyQuotationDIO modifyQuotationDIO) {
        com.zmn.common.dto2.ResponseDTO responseDTO;
        logger.info("[{}] 修改计价器订单报价：ModifyQuotationDIO={}", TAG,  JSON.toJSONString(modifyQuotationDIO));

        try {
            OperatePermissionVO operatePermission = orderWorkOperatePermissionBService
                    .getOperatePermission(modifyQuotationDIO.getOrderId(), modifyQuotationDIO.getWorkId(), OrderConsts.ORDER_OP_TYPE_MODIFY_QUOTATION);
            if (!operatePermission.getCanOperate()) {
                throw new OmsBaseException(operatePermission.getMsg());
            }
            ModifyQuotationDTO modifyQuotationDTO = BeanMapper.map(modifyQuotationDIO, ModifyQuotationDTO.class);
            this.setLogParam(modifyQuotationDIO, modifyQuotationDTO);
            modifyQuotationDTO.setOperatorId(modifyQuotationDIO.getMasterId().longValue());

            // 计价器订单修改产品，不会变更订单的计价器类型，不需要后台判断
            modifyQuotationDTO.setServItemType(OrderConsts.SERVICE_ITEM_TYPE_FAULT);
            modifyQuotationDTO.setQuotationType(GlobalConsts.OPERATE_USER_TYPE_MASTER);

            // 更新报价
            zsOrderWorkBService.updateOrderQuotation(modifyQuotationDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(modifyQuotationDIO.getPlat(),
                    modifyQuotationDIO.getOrderId(), modifyQuotationDIO.getWorkId(), modifyQuotationDIO.getMasterId(),
                    modifyQuotationDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            responseDTO = com.zmn.common.dto2.ResponseDTO.success(workDetailDRO, "OK");
        } catch  (Exception e) {
            responseDTO = com.zmn.common.dto2.ResponseDTO.fail(e.getMessage());
        }

        // 发送费用清单模版消息
        try {
            OrderWork orderWork = orderWorkService.findOrderWorkByKey(modifyQuotationDIO.getOrderId(), modifyQuotationDIO.getWorkId());
            sendOrderMessageService.sendDesignatedRuleIdMessage(orderWork.getOrderId(), MessageRuleIdConsts.MESSAGE_GLOBAL_QUOTATION_CONFIRM_NODE_MARK, MessageRuleIdConsts.ZMN_MSG_RULEID_QUOTATION_CONFIRM);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        return responseDTO;
    }

    /**
     * 发送用户报价模板消息
     * @param masterWorkDIO
     */
    @Override
    public com.zmn.common.dto2.ResponseDTO<Boolean> sendQuotationWechatTemplate(MasterWorkDIO masterWorkDIO) {
        OrderWork orderWork = orderWorkService.findOrderWorkByKey(masterWorkDIO.getOrderId(), masterWorkDIO.getWorkId());
        // boolean isSuccess = sendWechatTemplateService.sendQuotationTemplate(orderWork);
        boolean isSuccess = sendOrderMessageService.sendDesignatedRuleIdMessage(orderWork.getOrderId(), MessageRuleIdConsts.MESSAGE_GLOBAL_QUOTATION_NODE_MARK, MessageRuleIdConsts.ZMN_MSG_RULEID_QUOTATION);
        return com.zmn.common.dto2.ResponseDTO.success(isSuccess);
    }

    /**
     * 工程师修改订单产品
     */
    @Override
    public ResponseDTO<WorkDetailDRO> updateProduct(ModifyProductDIO modifyProductDIO) {
        ResponseDTO responseDTO;

        logger.info("[{}] 修改修改订单产品：ModifyProductDIO={}", TAG,  JSON.toJSONString(modifyProductDIO));

        try {
            OperatePermissionVO operatePermission = orderWorkOperatePermissionBService
                    .getOperatePermission(modifyProductDIO.getOrderId(), modifyProductDIO.getWorkId(), OrderConsts.ORDER_OP_TYPE_MODIFY_PRODUCT);
            if (!operatePermission.getCanOperate()) {
                throw new OmsBaseException(operatePermission.getMsg());
            }
            ModifyProductDTO modifyProductDTO = BeanMapper.map(modifyProductDIO, ModifyProductDTO.class);
            this.setLogParam(modifyProductDIO, modifyProductDTO);

            // 修改产品，有可能修改订单计价器类型，清空，由后台判断是否修改
            modifyProductDTO.setServItemType(null);

            orderWorkModifyProductBService.updateOrderProductByMaster(modifyProductDTO);

            // 返回更新后的工单详情
            WorkDetailDTO workDetail = zsMasterWorkBService.getWorkDetailSrcMaster(modifyProductDIO.getPlat(),
                    modifyProductDIO.getOrderId(), modifyProductDIO.getWorkId(), modifyProductDIO.getMasterId(),
                    modifyProductDIO.getAgent());
            WorkDetailDRO workDetailDRO = BeanMapper.map(workDetail, WorkDetailDRO.class);

            responseDTO = ResponseUtil.responseSuccess(workDetailDRO, "OK");
        } catch  (Exception e) {
            logger.error(e.getMessage(), e);
            responseDTO = super.responseDTO(e);
        }
        return responseDTO;
    }

    @Override
    public ResponseDTO<Boolean> checkUpdateProduct(ModifyProductDIO modifyProductDIO) {
        ResponseDTO responseDTO;

        try {
            ModifyProductDTO modifyProductDTO = BeanMapper.map(modifyProductDIO, ModifyProductDTO.class);
            String resultMessage = orderWorkModifyProductBService.checkUpdateProduct(modifyProductDTO);
            if (StringUtil.isBlank(resultMessage)) {
                responseDTO = ResponseUtil.responseSuccess(true, "OK");
            } else {
                responseDTO = ResponseUtil.responseFail(resultMessage);
            }
        } catch  (Exception e) {
            responseDTO = super.responseDTO(e);
        }
        return responseDTO;
    }

    /**
     * 获取工单可派单工程师列表
     * @param masterWorkDIO
     */
    @Override
    public ResponseDTO<WorkDistributeMasterDRO> getWorkDistributeMasterList(MasterWorkDIO masterWorkDIO) {
        ResponseDTO responseDTO;

        try {
            WorkDistributeMasterDTO workDistributeMasterDTO = zsMasterWorkBService.getWorkDistributeMasterList(
                    masterWorkDIO.getOrderId(), masterWorkDIO.getWorkId());
            WorkDistributeMasterDRO workDistributeMasterDRO = BeanMapper.map(workDistributeMasterDTO,
                    WorkDistributeMasterDRO.class);
            responseDTO = ResponseUtil.responseSuccess(workDistributeMasterDRO, "OK");
        } catch (Exception e) {
            responseDTO = super.responseDTO(e);
        }

        return responseDTO;
    }

    /**
     * 用户报价显示相关信息
     * @param quotationShowDIO
     */
    @Override
    public com.zmn.common.dto2.ResponseDTO<WorkQuotationShowDRO> getQuotationShow(BaseRequestDIO quotationShowDIO){
        OrderWork orderWork = orderWorkService.findOrderWorkByKey(quotationShowDIO.getOrderId(), quotationShowDIO.getWorkId());
        WorkQuotationShowDTO workQuotationShowDTO = zsMasterWorkBService.getQuotationShow(orderWork);
        WorkQuotationShowDRO workQuotationShowDRO = BeanMapper.map(workQuotationShowDTO,WorkQuotationShowDRO.class);
        return com.zmn.common.dto2.ResponseDTO.success(workQuotationShowDRO);
    };
}
